package com.tj.collection.controller.lending.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.DateUtil;
import com.tj.collection.db.entity.ClOutboundBatchEntity;
import com.tj.collection.db.entity.ClOutboundDetailEntity;
import com.tj.collection.db.entity.business.ClOutboundInfoEntity;
import com.tj.collection.enums.OutboundDetailStatusEnum;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/3/5
 * Time: 下午4:49
 */
public class ClOutboundQueryResponse implements ResponseData {

    private List<Item> outboundList;

    private OneItem outboundInfo;

    private Integer count;

    public ClOutboundQueryResponse(List<ClOutboundInfoEntity> clOutboundInfoEntityList) {
        this.outboundList = new ArrayList<>();
        for (ClOutboundInfoEntity entity : clOutboundInfoEntityList) {
            Item item = new Item();
            BeanUtils.copyProperties(entity, item);
            item.setCallStartTime(DateUtil.getDateTime(entity.getCallStartTime()));
            item.setAnswerTime(DateUtil.getDateTime(entity.getAnswerTime()));
            item.setHangupTime(DateUtil.getDateTime(entity.getHangupTime()));
            item.setCallDate(DateUtil.getDateTime(entity.getCallDate()));
            OutboundDetailStatusEnum detailStatusEnum = OutboundDetailStatusEnum.getEnum(entity.getStatus());
            item.setStatus(detailStatusEnum == null ? (entity.getStatus() + "") : detailStatusEnum.getDesc());
            this.outboundList.add(item);
        }
    }

    public ClOutboundQueryResponse(ClOutboundBatchEntity clOutboundBatchEntity, ClOutboundDetailEntity clOutboundDetailEntity) {
        OutboundDetailStatusEnum detailStatusEnum = OutboundDetailStatusEnum.getEnum(clOutboundDetailEntity.getStatus());

        this.outboundInfo = new OneItem()
                .setBatchNo(clOutboundDetailEntity.getBatchNo())
                .setTradeNo(clOutboundDetailEntity.getTradeNo())
                .setMobile(clOutboundDetailEntity.getMobile())
                .setStatus(detailStatusEnum == null ? (clOutboundDetailEntity.getStatus() + "") : detailStatusEnum.getDesc())
                .setAttach(clOutboundDetailEntity.getAttach())
                .setParams(clOutboundDetailEntity.getParams())
                .setCallStartTime(DateUtil.getDateTime(clOutboundDetailEntity.getCallStartTime()))
                .setAnswerTime(DateUtil.getDateTime(clOutboundDetailEntity.getAnswerTime()))
                .setDuration(clOutboundDetailEntity.getDuration())
                .setBillSec(clOutboundDetailEntity.getBillSec())
                .setHangupTime(DateUtil.getDateTime(clOutboundDetailEntity.getHangupTime()))
                .setHangupDirection(clOutboundDetailEntity.getHangupDirection())
                .setAccurateIntent(clOutboundDetailEntity.getAccurateIntent())
                .setReason(clOutboundDetailEntity.getReason())
                .setRemarks(clOutboundDetailEntity.getRemarks())
                .setFreason(clOutboundDetailEntity.getFreason())
                .setDetailList(clOutboundDetailEntity.getDetailList())
                .setMerchantCode(clOutboundBatchEntity.getMerchantCode())
                .setProductCategory(clOutboundBatchEntity.getProductCategory())
                .setProductCode(clOutboundBatchEntity.getProductCode())
                .setCallDate(DateUtil.getDateTime(clOutboundBatchEntity.getCallDate()))
                .setBotenceId(clOutboundBatchEntity.getBotenceId());

    }

    public ClOutboundQueryResponse(Integer count) {
        this.count = count;
    }

    public ClOutboundQueryResponse() {
    }

    public List<Item> getOutboundList() {
        return outboundList;
    }

    public ClOutboundQueryResponse setOutboundList(List<Item> outboundList) {
        this.outboundList = outboundList;
        return this;
    }

    public OneItem getOutboundInfo() {
        return outboundInfo;
    }

    public ClOutboundQueryResponse setOutboundInfo(OneItem outboundInfo) {
        this.outboundInfo = outboundInfo;
        return this;
    }

    private class Item {
        /**
         * 外呼批次号
         */
        private String batchNo;
        /**
         * 订单号
         */
        private String tradeNo;
        /**
         * 手机号
         */
        private String mobile;
        /**
         * 状态 0-未呼叫 1-呼叫成功 2-呼叫失败
         */
        private String status;
        /**
         * 拨打时间
         */
        private String callStartTime;
        /**
         * 应答时间
         */
        private String answerTime;
        /**
         * 通话结束时间
         */
        private String hangupTime;
        /**
         * 商户标识
         */
        private String merchantCode;
        /**
         * 产品类目
         */
        private String productCategory;
        /**
         * 产品code
         */
        private String productCode;
        /**
         * 拨打日期
         */
        private String callDate;
        /**
         * 话术模板id
         */
        private String botenceId;
        /**
         * 接听时长 秒
         */
        private Integer billSec;

        public String getBatchNo() {
            return batchNo;
        }

        public Item setBatchNo(String batchNo) {
            this.batchNo = batchNo;
            return this;
        }

        public String getTradeNo() {
            return tradeNo;
        }

        public Item setTradeNo(String tradeNo) {
            this.tradeNo = tradeNo;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public Item setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public String getStatus() {
            return status;
        }

        public Item setStatus(String status) {
            this.status = status;
            return this;
        }

        public String getCallStartTime() {
            return callStartTime;
        }

        public Item setCallStartTime(String callStartTime) {
            this.callStartTime = callStartTime;
            return this;
        }

        public String getAnswerTime() {
            return answerTime;
        }

        public Item setAnswerTime(String answerTime) {
            this.answerTime = answerTime;
            return this;
        }

        public String getHangupTime() {
            return hangupTime;
        }

        public Item setHangupTime(String hangupTime) {
            this.hangupTime = hangupTime;
            return this;
        }

        public String getMerchantCode() {
            return merchantCode;
        }

        public Item setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
            return this;
        }

        public String getProductCategory() {
            return productCategory;
        }

        public Item setProductCategory(String productCategory) {
            this.productCategory = productCategory;
            return this;
        }

        public String getProductCode() {
            return productCode;
        }

        public Item setProductCode(String productCode) {
            this.productCode = productCode;
            return this;
        }

        public String getCallDate() {
            return callDate;
        }

        public Item setCallDate(String callDate) {
            this.callDate = callDate;
            return this;
        }

        public String getBotenceId() {
            return botenceId;
        }

        public Item setBotenceId(String botenceId) {
            this.botenceId = botenceId;
            return this;
        }

        public Integer getBillSec() {
            return billSec;
        }

        public Item setBillSec(Integer billSec) {
            this.billSec = billSec;
            return this;
        }
    }

    private class OneItem {
        /**
         * 外呼批次号
         */
        private String batchNo;
        /**
         * 订单号
         */
        private String tradeNo;
        /**
         * 手机号
         */
        private String mobile;
        /**
         * 状态 0-未呼叫 1-呼叫成功 2-呼叫失败
         */
        private String status;
        /**
         * 附加参数
         */
        private String attach;
        /**
         * 参数
         */
        private String params;
        /**
         * 拨打时间
         */
        private String callStartTime;
        /**
         * 应答时间
         */
        private String answerTime;
        /**
         * 呼叫时长 秒
         */
        private Integer duration;
        /**
         * 接听时长 秒
         */
        private Integer billSec;
        /**
         * 通话结束时间
         */
        private String hangupTime;
        /**
         * 挂断方 0-表示机器人挂断 1-表示用户挂断
         */
        private Integer hangupDirection;
        /**
         * 意向标签 根据话术规则 AI判定的标签 F、W 为未接通
         */
        private String accurateIntent;
        /**
         * 意向备注 AI 判定标签的理由
         */
        private String reason;
        /**
         * 备注信息
         */
        private String remarks;
        /**
         * F 类明细
         */
        private Integer freason;
        /**
         * 对话明细
         */
        private String detailList;


        /**
         * 商户标识
         */
        private String merchantCode;
        /**
         * 产品类目
         */
        private String productCategory;
        /**
         * 产品code
         */
        private String productCode;
        /**
         * 拨打日期
         */
        private String callDate;
        /**
         * 话术模板id
         */
        private String botenceId;

        public String getBatchNo() {
            return batchNo;
        }

        public OneItem setBatchNo(String batchNo) {
            this.batchNo = batchNo;
            return this;
        }

        public String getTradeNo() {
            return tradeNo;
        }

        public OneItem setTradeNo(String tradeNo) {
            this.tradeNo = tradeNo;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public OneItem setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public String getStatus() {
            return status;
        }

        public OneItem setStatus(String status) {
            this.status = status;
            return this;
        }

        public String getAttach() {
            return attach;
        }

        public OneItem setAttach(String attach) {
            this.attach = attach;
            return this;
        }

        public String getParams() {
            return params;
        }

        public OneItem setParams(String params) {
            this.params = params;
            return this;
        }

        public String getCallStartTime() {
            return callStartTime;
        }

        public OneItem setCallStartTime(String callStartTime) {
            this.callStartTime = callStartTime;
            return this;
        }

        public String getAnswerTime() {
            return answerTime;
        }

        public OneItem setAnswerTime(String answerTime) {
            this.answerTime = answerTime;
            return this;
        }

        public Integer getDuration() {
            return duration;
        }

        public OneItem setDuration(Integer duration) {
            this.duration = duration;
            return this;
        }

        public Integer getBillSec() {
            return billSec;
        }

        public OneItem setBillSec(Integer billSec) {
            this.billSec = billSec;
            return this;
        }

        public String getHangupTime() {
            return hangupTime;
        }

        public OneItem setHangupTime(String hangupTime) {
            this.hangupTime = hangupTime;
            return this;
        }

        public Integer getHangupDirection() {
            return hangupDirection;
        }

        public OneItem setHangupDirection(Integer hangupDirection) {
            this.hangupDirection = hangupDirection;
            return this;
        }

        public String getAccurateIntent() {
            return accurateIntent;
        }

        public OneItem setAccurateIntent(String accurateIntent) {
            this.accurateIntent = accurateIntent;
            return this;
        }

        public String getReason() {
            return reason;
        }

        public OneItem setReason(String reason) {
            this.reason = reason;
            return this;
        }

        public String getRemarks() {
            return remarks;
        }

        public OneItem setRemarks(String remarks) {
            this.remarks = remarks;
            return this;
        }

        public Integer getFreason() {
            return freason;
        }

        public OneItem setFreason(Integer freason) {
            this.freason = freason;
            return this;
        }

        public String getDetailList() {
            return detailList;
        }

        public OneItem setDetailList(String detailList) {
            this.detailList = detailList;
            return this;
        }

        public String getMerchantCode() {
            return merchantCode;
        }

        public OneItem setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
            return this;
        }

        public String getProductCategory() {
            return productCategory;
        }

        public OneItem setProductCategory(String productCategory) {
            this.productCategory = productCategory;
            return this;
        }

        public String getProductCode() {
            return productCode;
        }

        public OneItem setProductCode(String productCode) {
            this.productCode = productCode;
            return this;
        }

        public String getCallDate() {
            return callDate;
        }

        public OneItem setCallDate(String callDate) {
            this.callDate = callDate;
            return this;
        }

        public String getBotenceId() {
            return botenceId;
        }

        public OneItem setBotenceId(String botenceId) {
            this.botenceId = botenceId;
            return this;
        }
    }
}
